<?php

/**
 * This is the model class for table "transaction_history".
 *
 * The followings are the available columns in table 'transaction_history':
 * @property string $transaction_history_id
 * @property string $transaction_id
 * @property string $transaction_date
 * @property string $particulars
 * @property double $debit
 * @property double $credit
 * @property double $balance
 * @property string $payment_processors_id
 * @property string $create_date
 * @property string $create_by
 * @property string $update_date
 * @property string $update_by
 * @property string $status
 * @property string $ref_id
 *
 * The followings are the available model relations:
 * @property PaymentProcessor $paymentProcessors
 */
class TransactionHistory extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return TransactionHistory the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'transaction_history';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('transaction_date', 'required'),
            array('debit, credit, balance', 'numerical'),
            array('transaction_id, payment_processors_id, create_by, update_by,ref_id', 'length', 'max' => 10),
            array('particulars', 'length', 'max' => 512),
            array('status', 'length', 'max' => 45),
            array('create_date, update_date', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('transaction_history_id, transaction_id, transaction_date, particulars, debit, credit, balance, payment_processors_id, create_date, create_by, update_date, update_by, status', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'paymentProcessors' => array(self::BELONGS_TO, 'PaymentProcessor', 'payment_processors_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'transaction_history_id' => 'Transaction History',
            'transaction_id' => 'Transaction',
            'transaction_date' => 'Transaction Date',
            'particulars' => 'Particulars',
            'debit' => 'Debit',
            'credit' => 'Credit',
            'balance' => 'Balance',
            'payment_processors_id' => 'Payment Processors',
            'create_date' => 'Create Date',
            'create_by' => 'Create By',
            'update_date' => 'Update Date',
            'update_by' => 'Update By',
            'status' => 'Status',
        	'ref_id' => 'Ref ID',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('transaction_history_id', $this->transaction_history_id, true);
        $criteria->compare('transaction_id', $this->transaction_id, true);
        $criteria->compare('transaction_date', $this->transaction_date, true);
        $criteria->compare('particulars', $this->particulars, true);
        $criteria->compare('debit', $this->debit);
        $criteria->compare('credit', $this->credit);
        $criteria->compare('balance', $this->balance);
        $criteria->compare('payment_processors_id', $this->payment_processors_id, true);
        $criteria->compare('create_date', $this->create_date, true);
        $criteria->compare('create_by', $this->create_by, true);
        $criteria->compare('update_date', $this->update_date, true);
        $criteria->compare('update_by', $this->update_by, true);
        $criteria->compare('status', $this->status, true);
        $criteria->compare('ref_id', $this->ref_id, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

}